package SourceReading;

import org.junit.jupiter.api.Test;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Instruction：
 * Author：@author MaLi
 */
public class SR01_Executor {
    @Test
    public void readExecutor() {
        //定义执行器
        Executor executor = new Executor() {
            @Override
            public void execute(Runnable command) {
                new Thread(command).start();//启动线程
            }
        };

        //启动执行器
        executor.execute(()->{
            System.out.println(Thread.currentThread().getName()+" --> 通过执行器直接提交一个任务");
        });
    }

    public void readSubmit() {
        ExecutorService pool = Executors.newFixedThreadPool(1);
        Future<?> future = pool.submit(() -> {
            System.out.println("do nothing");
        });
    }
}
